/**
 * 
 */
package fr.gfi.agraf.vue.action.administrer.perimetre;

import org.apache.log4j.Logger;

import fr.gfi.agraf.exception.AgrafException;
import fr.gfi.agraf.service.IPerimetreService;
import fr.gfi.agraf.utils.PropertiesUtils;
import fr.gfi.agraf.utils.SpringFactory;
import fr.gfi.agraf.vue.action.AbstractApplicationSupportAction;

/**
 * @author Fw
 * 
 */
public class SupprimerPerimetreAction extends AbstractApplicationSupportAction {

	/**
	 * Logger
	 */
	private final static Logger LOGGER = Logger.getLogger(SupprimerPerimetreAction.class);

	/**
	 * Généré par Java
	 */
	private static final long serialVersionUID = -1008338932806989459L;

	private static final String PERIMETRE_SERVICE = "PerimetreService";

	private static final String ERREUR_DONNEES_INCOHERENTE = "erreur.donnees.incoherente.modifier.perimetre";

	private Long idPerimetre;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * fr.gfi.agraf.vue.action.AbstractApplicationSupportAction#executeAction()
	 */
	@Override
	public String executeAction() throws Exception {

		if (idPerimetre == null) {
			addActionError(PropertiesUtils.getProperty(ERREUR_DONNEES_INCOHERENTE));
			return ERROR;
		}

		final IPerimetreService perimetreService = (IPerimetreService) SpringFactory.getApplicationContext()
				.getBean(PERIMETRE_SERVICE);
		try {
			perimetreService.supprimerPerimetre(idPerimetre, getUtilisateurConnecte().getId());
		} catch (final AgrafException e) {
			final String messageErreur = PropertiesUtils.getProperty(e.getKey());
			addActionError(messageErreur);
			LOGGER.error(messageErreur, e);
			return ERROR;
		}

		return SUCCESS;
	}

	/**
	 * @return the idPerimetre
	 */
	public Long getIdPerimetre() {
		return idPerimetre;
	}

	/**
	 * @param idPerimetre
	 *            the idPerimetre to set
	 */
	public void setIdPerimetre(final Long idPerimetre) {
		this.idPerimetre = idPerimetre;
	}

}
